var express = require('express');
const Result = require('../lib/Result');
const isRule = require('../util/isRule');
const Category = require('../db/models/category/category');
const UserLevel = require('../db/models/user/user_level');
var router = express.Router();
/**
 * 会员等级列表,102,22,173
 */
router.get(":page",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [102,22,173], res, token.super)) {
        let page=req.params.page
        let limit=req.query.limit? req.query.limit:10
        UserLevel.getLevelList(page,limit).then(value=>{
            res.json(Result.success(value))
        })
    }
})
/**
 * 增加会员等级,103,22,173
 */
router.post("",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [103,22,173], res, token.super)) {
        UserLevel.addLevel(req.body).then(value=>{
            res.json(Result.success(value))
        })
    }
})
/**
 * 修改会员等级状态,105,22,173
 */
router.post("/:id/update_status",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [105,22,173], res, token.super)) {
        UserLevel.addLevel(req.body,req.params.id).then(value=>{
            res.json(Result.success(true))
        })
    }
})
/**
 * 删除会员等级,106,22,173
 */
router.post("/:id/delete",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [106,22,173], res, token.super)) {
        UserLevel.deleteByid(req.params.id).then(value=>{
            res.json(Result.success(true))
        })
    }
})
/**
 * 修改会员等级,104,22,173
 */
router.post("/:id",(req,res)=>{
    let token = req.auth
    if (isRule(token.rule, [104,22,173], res, token.super)) {
        UserLevel.addLevel(req.body,req.params.id).then(value=>{
            res.json(Result.success(true))
        })
    }
})
module.exports=router